<template>
  <Button
    label="重置"
    icon="pi pi-refresh"
    severity="secondary"
    :loading="loading"
    @click="resetHandler"
  />
</template>
<script>
export default {
  name: 'ResetButton',
  props: {
    loading: {
      type: Boolean,
      required: false,
      default: () => {
        return false
      },
    },
    searchForm: {
      type: Object,
      required: true,
    },
    search: {
      type: Function,
      required: true,
    },
  },
  methods: {
    resetHandler() {
      for (const key in this.searchForm) {
        if (typeof this.searchForm[key] == 'number') {
          delete this.searchForm[key]
        } else {
          this.searchForm[key] = ''
        }
      }
      this.search(1)
    },
  },
}
</script>
